<!DOCTYPE html>
<html lang="en" >
<head >
    <meta charset="utf-8" >
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" >
    <meta name="description" content="" >
    <meta name="author" content="ThemeBucket" >
    <link rel="shortcut icon" href="#" type="image/png" >

    <title >Form Layouts</title >
    <link href="/public/js/summernote/dist/summernote.css" rel="stylesheet" >
    <link rel="stylesheet" type="text/css" href="/public/js/imageuploader/styles.imageuploader.css" />
    <!--nestable css-->
    <link rel="stylesheet" type="text/css" href="/public/js/nestable/jquery.nestable.css" />

    <link rel="stylesheet" type="text/css" href="/public/js/bootstrap-select-1.12.4/dist/css/bootstrap-select.css" />
    <script language="javascript" >
        function RunOnBeforeUnload() {window.onbeforeunload = function () { return ""; } }
    </script >
    <?php $this->load->view('library/header'); ?>
    <style type="text/css">
    .img-rounded {
            overflow: hidden;
        }
        .img-rounded img {
            width: 35px;
            padding: 0;
        }
    </style>

</head >

<body onload="RunOnBeforeUnload()" class="sticky-header" >

<section >
    <?php $this->load->view('library/left'); ?>

    <!-- main content start-->
    <div class="main-content" >

        <?php $this->load->view('library/top'); ?>

        <!-- page heading start-->
        <div class="page-heading" >
            <h3 >
                添加商品 </h3 >
            <ul class="breadcrumb" >
                <li >
                    <a href="#" >Forms</a >
                </li >
                <li class="active" > Forms Layouts</li >
            </ul >
        </div >
        <!-- page heading end-->

        <!--body wrapper start-->
        <section class="wrapper" >
            <!-- page start-->

            <div class="row" >
                <div class="col-lg-12" >
                    <section class="panel" >
                        <header class="panel-heading custom-tab turquoise-tab" >
                            <ul class="nav nav-tabs" >
                                <li class="active" >
                                    <a href="#home2" data-toggle="tab" >基础信息</a >
                                </li >
                                <li class="about2" style="display:none;">
                                    <a href="#about2" data-toggle="tab" >SKU信息</a >
                                </li >
                                <li class="" >
                                    <a href="#profile2" data-toggle="tab" >图片信息</a >
                                </li >
                                <li class="cont-form" >
                                    <a href="#contact2" data-toggle="tab" >产品描述</a >
                                </li >
                            </ul >
                        </header >
                        <div class=" form" >
                            <form
                                    class="cmxform form-horizontal adminex-form" id="commentForm" method="post"
                                    action="" >
                                <div class="panel-body" >
                                    <div class="tab-content" >
                                        <div class="tab-pane active" id="home2" >
                                            
                                            <div class="form-group " >
                                                <label for="cname" class="control-label col-lg-2" >商品英文名称<a href="#" class="zhuanhaun">转换</a></label >
                                                <div class="col-lg-10" >
                                                    <input
                                                            class=" form-control"
                                                            value="<?php echo $goods['cn_name']; ?>" name="cn_name"
                                                            type="text" />
                                                </div >
                                            </div >
                                            <div class="form-group " >
                                                <label for="curl" class="control-label col-lg-2" >类型</label >
                                                <div class="col-lg-2" >
                                                    <select name="goods_type" class="form-control" >
                                                        <option value="1" >采买</option >
                                                        <option value="2" >定制</option >
                                                    </select >
                                                </div >
                                            </div >
                                            <div class="form-group " >
                                                <label for="curl" class="control-label col-lg-2" >渠道</label >
                                                <div class="col-lg-2" >
                                                    <select name="channel_id" class="form-control" >
                                                        <option <?php echo $goods['channel_id'] == 3 ? 'selected="selected"' : ''; ?>
                                                                value="3" >供应商1688
                                                        </option >
                                                        <option <?php echo $goods['channel_id'] == 1 ? 'selected="selected"' : ''; ?>
                                                                value="1" >外网
                                                        </option >
                                                        <option <?php echo $goods['channel_id'] == 2 ? 'selected="selected"' : ''; ?>
                                                                value="2" >竞争对手
                                                        </option >

                                                    </select >
                                                </div >
                                            </div >
                                            <div class="form-group" >
                                                <label class="col-sm-2 col-sm-2 control-label" >采购员</label >
                                                <div class="col-sm-3" >
                                                    <select name="purchase_id" class="form-control" id="purchaseId">
                                                        <option value="0" >选择采购员</option >
                                                        <?php foreach ($purchase as $k => $val): ?>
                                                            <option value="<?php echo $val['e_id']; ?>" ><?php echo $val['purchase_name']; ?></option >
                                                        <?php endforeach; ?>
                                                    </select >
                                                </div >
                                            </div >
                                            <div class="form-group " >
                                                <label for="curl" class="control-label col-lg-2" >商品分类</label >
                                                <div class="col-lg-4" >
                                                    <select name="cat_id" class="form-control" >
                                                        <option >选择分类</option >
                                                        <?php foreach ($cate_option as $cate_id => $cate_name): ?>
                                                            <option <?php echo $goods['cat_id'] == $cate_id ? 'selected="selected"' : ''; ?>
                                                                    value="<?php echo $cate_id; ?>" ><?php echo $cate_name; ?></option >
                                                        <?php endforeach; ?>
                                                    </select >
                                                </div >
                                            </div >
                                            <div class="form-group " >
                                                <label for="cemail" class="control-label col-lg-2" >货号</label >
                                                <div class="col-lg-3" >
                                                    <select
                                                            name="suppliers_id" data-live-search-placeholder="搜索供应商"
                                                            data-live-search="true" class="form-control selectpicker" >
                                                        <option >选择供应商</option >
                                                        <?php foreach ($suppliers_option as $supp_id => $supp_name): ?>
                                                            <option <?php echo $goods['suppliers_id'] == $supp_id ? 'selected' : ''; ?>
                                                                    value="<?php echo $supp_id; ?>" ><?php echo $supp_name; ?></option >
                                                        <?php endforeach; ?>
                                                    </select >
                                                </div >
                                                <div class="col-lg-2" >
                                                    <select
                                                            name="admin_id" id="admin_id" data-live-search="true" disabled
                                                            class="form-control" >
                                                        <option >选择开发员</option >
                                                        <?php foreach ($admin_name as $_id => $val): ?>
                                                            <option <?php echo $admin_id == $_id ? 'selected' : ''; ?>
                                                                    value="<?php echo $_id; ?>" ><?php echo $val; ?></option >
                                                        <?php endforeach; ?>
                                                    </select >
                                                </div >
                                                <div class="col-lg-3" >
                                                    <input
                                                            class="form-control " id="goods_sn" readonly="readonly"
                                                            type="text" <?php echo $goods ? 'disabled' : ''; ?>
                                                            value="<?php echo $goods['goods_sn'] ? $goods['goods_sn'] : $goods_sn; ?>"
                                                            name="goods_sn" />
                                                </div >
                                            </div >
                                            
                                           
                                            <div class="form-group " >
                                                <label for="curl" class="control-label col-lg-2" >产品重量</label >
                                                <div class="col-lg-2" >
                                                    <div class="input-group" >
                                                        <input
                                                                type="text"
                                                                value="<?php echo $goods['goods_weight']; ?>"
                                                                name="goods_weight" class="form-control" > <span
                                                                class="input-group-addon" >G</span >
                                                    </div >
                                                </div >
                                            </div >

                                            


                                            
<div class="caimai_dingzhi" >
    <div class="form-group addsupp" >
        <label for="curl" class="control-label col-lg-2" >1688链接</label >
        <div class="col-lg-3" >
            <input class="form-control curl" type="text" value="" name="supp_url" />
        </div >
        
        <div class="col-lg-2" >
            <div class="input-group" >
                <span class="input-group-addon" >￥</span > <input
                        type="text" value="" name="in_price"
                        class="form-control in_price" placeholder="进货价" >
            </div >
        </div >
        <div class="col-lg-1" >
            <a class="get-goods" href="javascript:;" >获取信息</a >
        </div >
    </div >
    <div class="form-group" >
        <label for="curl" class="control-label col-lg-2" >1688商品名称</label >
        <div class="col-lg-6" >
            <input
                    class="form-control supp_name" type="text" value=""
                    name="ali_goods_name" />
        </div >
    </div >
    <div class="form-group " >
        <label for="curl" class="control-label col-lg-2" >价格</label >
        <div class="col-lg-2" >
            <div class="input-group" >
                <span class="input-group-addon" >$</span > <input
                        type="text" value="" name="shop_price" class="form-control"
                        placeholder="售价" >
            </div >
        </div >
    </div >
    <div class="form-group supp_sku" >
        <label class="control-label col-lg-2" >尺码颜色信息</label >
        <div class="col-lg-10 icheck" >
            <div class="col-lg-7 sku_color" >

            </div >
            <div class="col-lg-5 sku_size" >

            </div >
        </div >
    </div >
</div >
                                            
                                        </div >
                                        <div class="tab-pane" id="about2" >
                                            <button class="btn btn-info " id="add-size" type="button" ><i
                                                        class="fa fa-plus" ></i > 添加尺码
                                            </button >
                                            
                                            <table id="sku-list" class="table table-hover general-table" >
                                                <thead >
                                                <tr >
                                                    <th > 尺码</th >
                                                    <th class="hidden-phone" >图片</th >
                                                    <th class="hidden-phone" >颜色</th >
                                                    <th >操作</th >
                                                </tr >
                                                </thead >
                                                <tbody >
                                                
                                                    <tr >
                                                        <td >
                                                        <select name="sku[size][]" class="option-size form-control chooseSize">
                                                            <option value="">选择尺码</option>
                                                        <?php foreach($size_option as $k=>$v){?>
                                                            <option  value="<?php echo $v['size_id']?>"><?php echo $v['size_value']?></option>
                                                            <?php }?>
                                                        </select>
                                                            
                                                        </td >
                                                        <td style="width: 4%;">
                                                            <a href="#myModal" data-toggle="modal" class="img-rounded option-0"  style="float: left; margin-right: 15px; width: 35px; height: 35px; background-color: #8888;" data-id="0"></a>
                                                        </td>
                                                        
                                                        <td class="hidden-phone" >

                                                        <select name="sku[color][]" class="option-size form-control chooseSize">
                                                            <option value="0">选择颜色</option>
                                                            <?php foreach($colors_option as $k=>$v){?>
                                                            <option  value="<?php echo $v['color_id']?>"><?php echo $v['color_zh']?></option>
                                                            <?php }?>
                                                        </select>
                                                            
                                                        </td >
                                                        
                                                        <td >

                                                        </td >
                                                    </tr >
                                                
                                                </tbody >
                                            </table >
                                        </div >
                                        <div class="tab-pane" id="profile2" >
                                            <?php if ($goods['images']) : ?>
                                                <div
                                                        class="uploader__box js-uploader__box l-center-box dd bo"
                                                        id="nestable_list_1" >
                                                    <ol class="dd-list js-uploader__file-list uploader__file-list" >
                                                        <?php $i = 0;
                                                            foreach ($goods['images'] as $k => $image) : ?>
                                                                <li
                                                                        class="uploader__file-list__item dd-item"
                                                                        data-id="<?php echo $i + 1; ?>"
                                                                        data-sku-id="<?php echo $k; ?>"
                                                                        data-index="<?php echo $i; ?>" >
                                                            <span class="uploader__file-list__thumbnail dd-handle" >
                                                                <img
                                                                        class="thumbnail1"
                                                                        src="<?php echo $image['original_img']; ?>" >
                                                            </span > <span class="uploader__file-list__text" >timg-2.jpeg</span >
                                                                    <span class="uploader__file-list__size" >102 KB</span >
                                                                    <span class="uploader__file-list__button" ><button
                                                                                class="uploader__icon-button js-upload-remove-button fa fa-times"
                                                                                data-index="<?php echo $i; ?>" ></button ></span >
                                                                </li >
                                                                <?php $i++; endforeach; ?>
                                                    </ol >
                                                    <div class="js-uploader__contents uploader__contents uploader__hide" ></div >
                                                </div ><p
                                                        class="js-uploader__further-instructions uploader__further-instructions" ></p >
                                            <?php else: ?>
                                                <div
                                                        class="uploader__box js-uploader__box l-center-box dd"
                                                        id="nestable_list_1" >
                                                    <ol class="dd-list js-uploader__file-list uploader__file-list" ></ol >
                                                    <div class="js-uploader__contents uploader__contents" ></div >
                                                </div ><p
                                                        class="js-uploader__further-instructions uploader__further-instructions uploader__hide" ></p >
                                            <?php endif; ?>
                                        </div >
                                        <div class="tab-pane" id="contact2" >
                                            <div class="form-horizontal " >
                                                <div class="form-group" >
                                                    <div class="col-md-12" >
                                                        <textarea
                                                                id="summernote" name="summernote" class="form-control"
                                                                cols="4"
                                                                rows="9" ><?php echo $goods['body_html']; ?></textarea >
                                                        <div class="goods_attr">
                                                            <button type="button" class="btn btn-info btn-sm btn-add-row">添加行</button>
                                                            <button type="button" style="margin-left: 5px" class="btn btn-info btn-sm btn-add-col">添加列</button>
                                                            <button type="button" style="margin-left: 5px" class="btn btn-info btn-sm centimeter">点击转换为厘米</button>
                                                            
                                                                <table class="goods_attr_table table table-bordered" style="margin-top: 10px;">
                                                                    <thead>
                                                                    <tr>
                                                                        <th><input class="form-control" name="attr_title[0]" value="SIZE(IN)" /></th>
                                                                    </tr>
                                                                    </thead>
                                                                    <tbody class="not-add">
                                                                    </tbody>
                                                                </table>
                                                        </div>
                                                    </div >
                                                </div >
                                            </div >
                                        </div >
                                    </div >
                                </div >
                                <footer class="panel-footer" >
                                    <button
                                            type="submit" name="handle_type" value="0"
                                            class="btn btn-post pull-right btn-big" >提交信息
                                    </button >
                                    <ul class="nav nav-pills p-option" ></ul >
                                </footer >
                            </form >
                        </div >
                    </section >
                </div >
            </div >
            <!-- page end-->
        </section >
        <!--body wrapper end-->

        <!--footer section start-->
        <footer >
            2014 &copy; AdminEx by
        </footer >
        <!--footer section end-->


    </div >
    <!-- main content end-->

    <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">Form Tittle</h4>
            </div>
            <div class="modal-body">
                <div class="row"></div>
            </div>
        </div>
    </div>
</div>

    <div
            aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModala"
            class="modal fade" >
        <div class="modal-dialog" >
            <div class="modal-content" >
                <div class="modal-header" >
                    <button aria-hidden="true" data-dismiss="modal" class="close" type="button" >×</button >
                    <h4 class="modal-title" >Form Tittle</h4 >
                </div >
                <div class="modal-body" >
                    <div class="rowa" ></div >
                </div >
            </div >
        </div >
    </div >
</section >

<script src="/public/js/express-art-template-master/template-web.js" ></script >

<script type="text/html" id="color_temp" >
    <% for(var i = 0; i < items.length; i++){ %>
    <div class="row" style="margin-top: 15px; margin-left: -30px;" >
        <div class="col-lg-6" >
            <img width="35" src="<%=items[i].imageUrl%>" class="img-rounded" style="float: left; margin-right: 15px;" />
            <input
                    style="float: left; width: 200px;" value="<%=items[i].name%>" name="aliyun_sku[ali_color][]"
                    readonly="readonly" class="form-control sunjian_ali_color" >
        </div >
        <a href="#myModal" data-toggle="modal" class="img-rounded option-<%=i%>" data-id="<%=i%>" style="float: left; margin-right: 15px; width: 35px; height: 35px; background-color: #8888;"></a>
        <div class="col-lg-5" >
            <select name="sku[color][]" class="option-color form-control sunjian_color supp_sku_color" >
                <option value="" >选择颜色</option >
                <?php foreach($colors_option as $k=>$v){?>
                    <option  value="<?php echo $v['color_id']?>"><?php echo $v['color_zh']?></option>
                <?php }?>
            </select >
        </div >
    </div ><% } %>
</script >
<script type="text/html" id="size_temp" >
    <% for(var i = 0; i < items.length; i++){ %>
    <div class="row" style="margin-top: 15px;" >
        <div class="col-lg-4" >
            <input
                    value="<%=items[i].name%>" name="aliyun_sku[ali_size][]" readonly="readonly"
                    class="form-control sunjian_ali_size" >
        </div >
        <div class="col-lg-6" >
            <select name="sku[size][]" class="option-size form-control sunjian_size supp_sku_size" >

                <option value="" >选择尺码</option >
                <?php foreach($size_option as $k=>$v){?>
                    <option  value="<?php echo $v['size_id']?>"><?php echo $v['size_value']?></option>
                <?php }?>
            </select >
        </div >
    </div ><% } %>
</script >
<script >
$(document).on('click','.img-rounded', function () {
            $('#myModal .modal-body .row').html('');
            var data_goods_id = $(this).attr('data-id');
           $('.uploader__file-list__item').each(function (i) {

               var data_id = $(this).attr('data-index');
               var html = '<div style="text-align: center;" data-goods-id="' + data_goods_id + '" class="col-lg-3 add_img" data-id="' + data_id + '">' + $(this).find('.uploader__file-list__thumbnail').html() + '</div>';
               $('#myModal .modal-body .row').append(html);
           });
        });
$('.modal-body').on('click', '.add_img', function () {
            var data_id = $(this).attr('data-id');
            var data_goods_id = $(this).attr('data-goods-id');
            var html = '<input type="hidden" name="sku[color_img]['+ data_goods_id + ']" value="' + data_id + '" />';
            $('.option-'+data_goods_id).html($(this).html()+html);
        });
    $("select[name = 'goods_type']").change(function(){
        var val = $(this).val();
        if(val == 2){
            $('.about2').show();
            $('.get-goods').hide();
        }else{
            $('.about2').hide();
            $('.get-goods').show();
        }
    })
    var img_html = '';
    $ (document).on ("click", '.clickimg', function () {
        img_html = $ (this);
        $ ('.rowa').html ('');
        $ (".uploader__file-list__item .thumbnail1").each (function () {
            var b = $ (this).attr ('src');
            img_index = $ ($ (this).closest ('li')).attr ('data-index')

            $ ('.rowa').append ('<img  data-index="' + img_index + '" class="thumbnail1 img" style="margin-left:30px" src="' + b + '">');
        })
    })


        $ (document).on ('click', '.get-goods', function () {
            var supp = $ (this).parents ('.addsupp').find ('.curl').val ();

            thisg = $ (this);

            $ (this).html ('获取中...');
            //var supp_id = $ ('.selectpicker').val ();
            $.post ("<?php echo base_url('Baby/ajax_ali_goods');?>", {
                ali_url: supp,
                //supp_id: supp_id
            }, function (aliData) {
                var result_color = '', result_size = '';
                var data = aliData.data;

                // thisg.parents ('.addsupp').find ('.supp_sn').val (data.ali_sn);
                thisg.parents ('.addsupp').find ('.in_price').val (data.ali_price);
                thisg.parents ('.addsupp').find ('.g_supp_id').val (data.g_supp_id);

                $ ('.supp_name').val (data.title);

                if (data.skuProps) {
                    for (var x in data.skuProps) {

                        var obj = {
                            items: data.skuProps[ x ].value
                        };

                        if (data.skuProps[ x ].prop === '颜色') {
                            console.log(obj);
                            result_color += template ('color_temp', obj);
                        }else if (data.skuProps[ x ].prop === '尺码') {
                            result_size += template ('size_temp', obj);
                        }
                    }

                    $ ('.supp_sku .sku_color').html (result_color);
                    $ ('.supp_sku .sku_size').html (result_size);
                    $ ('.flat-green input').iCheck ({
                        checkboxClass: 'icheckbox_flat-green',
                        radioClass: 'iradio_flat-green'
                    });
                }


            }, 'json');
        });


    $ (document).on ("click", '.img', function () {
        var src = $ (this).attr ('src');
        var img_index = $ (this).attr ('data-index');
        console.log (img_html)
        color_value = img_html.closest ('tr').find ('.option-color').val ()

        img_text = '<img  data-id="' + img_index + '" src="' + src + '" style="width: 40px;height: 40px;"><input type="hidden" name="pro_imgs[]" value="' + img_index + '">'
        $ ('.option-color option[value="' + color_value + '"]:checked').closest ('tr').find ('.clickimg').html (img_text)
    })
    $('.zhuanhaun').click(function(){
        var goods_name = $("input[name='cn_name']").val();
        $("input[name='cn_name']").val(replaceStr(goods_name));
    })

    function replaceStr(str) {
        var strTemp = ""; //新字符串
        for(var i = 0; i < str.length; i++) {
            if(i == 0) {
            strTemp += str[i].toUpperCase(); //第一个
            continue;
            }
            if(str[i] == " ") { //空格后
            strTemp += " ";
            strTemp += str[i + 1].toUpperCase();
            i++;
            continue;
            }
            if(str[i] == "-") { //-后
            strTemp += "-";
            strTemp += str[i + 1].toUpperCase();
            i++;
            continue;
            }
            strTemp += str[i];
        }
        return strTemp;
    }
</script >
<?php $this->load->view('library/footer'); ?>

<!--编辑器-->
<script src="/public/js/summernote/dist/summernote.js" ></script >
<script src="/public/js/summernote/dist/lang/summernote-zh-CN.js" ></script >

<script src="/public/js/bootstrap-select-1.12.4/dist/js/bootstrap-select.min.js" ></script >

<script src="/public/js/imageuploader/jquery.imageuploader.js" ></script >

<script src="/public/js/nestable/jquery.nestable.js" ></script >
<script src="/public/js/nestable-init.js" ></script >

<!--common scripts for all pages-->
<script src="/public/js/scripts.js" ></script >
<script >
    $ ('.color_sort').click (function () {
        var arr = new Array ();
        var goods_id = "<?php echo $goods['goods_id'];?>";
        $ ('.column').each (function () {
            var sort = parseFloat ($ (this).attr ('sort')) + 1;
            var color = $ (this).children ('.box1').attr ('color');
            arr.push ({sort: sort, color: color, goods_id: goods_id});
        })
        $.ajax ({
            type: 'post',
            url: "<?php echo base_url('Product/update_color')?>",
            dataType: 'json',
            data: {
                arr: arr,
            },
            success: function (data) {
                swal ({
                    title: data.info,
                    text: '2秒后关闭',
                    type: data.status,
                    allowOutsideClick: false,
                    timer: 1500,
                    showConfirmButton: false
                })
                top.location.reload ()
            }
        })
    })

    jQuery (document).ready (function () {

        var yi = <?php echo $_k_title + 1;?>;

        $ ('.cont-form').click (function () {

            size = [];

            $ ('.option-size').each (function (index, element) {
                size[ $ (this).val () ] = $ (this).val ();
            });
            for (x in size) {
                $ ('.goods_attr_table tbody.not-add').append ('<tr><td><input class="form-control" name="attr_val[0][]" value="' + size[ x ] + '" /></td><td class="row-del"><a href="javascript:;">删除</td></tr>');
            }
            $ ('.goods_attr_table tbody.not-add').append ('<tr class="tr-del"><td></td></tr>');
            $ ('.goods_attr_table tbody.not-add').removeClass ('not-add');
        });

        $ ('.btn-add-col').click (function () {
            $ ('.goods_attr_table thead tr').append ('<th><input class="form-control" name="attr_title[' + yi + ']" value="" /></th>');
            $ ('.goods_attr_table tbody tr:not(.tr-del) td:last-child').before ('<td><input class="form-control" name="attr_val[' + yi + '][]" value="" /></td>');
            $ ('.goods_attr_table tbody tr.tr-del').append ('<td><a href="javascript:;">删除</a></td>');

            yi++;
        });
        $ ('.btn-add-row').click (function () {
            var html = $ ('.goods_attr_table tbody tr:not(.tr-del):last').html ();
            $ ('.goods_attr_table tbody tr.tr-del ').before ('<tr>' + html + '</tr>');
        });

        $ ('.tr-del td a').live ("click", function () {
            var del = confirm ("您确定要删除此条记录？");
            if (del == true) {
                var a_eq = $ (this).parent ('td').index ();

                $ ('.goods_attr_table thead tr th:eq(' + a_eq + ')').remove ();
                $ ('.goods_attr_table tbody tr').each (function () {
                    $ (this).find ('td:eq(' + a_eq + ')').remove ();
                });
            }
            else {
                return false;
            }
        });

        $ ('.row-del a').live ('click', function () {
            var del = confirm ("您确定要删除此条记录？");
            if (del == true) {
                var a_eq = $ (this).parents ('tr').index ();
                $ ('.goods_attr_table tbody tr:eq(' + a_eq + ')').remove ();
            }
            else {
                return false;
            }
        });

        $ ('.selectpicker').selectpicker ({
            size: 6
        });

        //添加SKU
        $ ('#add-size').click (function () {
            var strVar = $ ('#sku-list tr:last').clone (true);
            strVar.find ('a').removeClass ('option-'+strVar.find ('a').attr('data-id'));
            strVar.find ('a').addClass ('img-rounded');
            strVar.find ('a').addClass ('option-'+(Number(strVar.find ('a').attr('data-id'))+1));
            strVar.find ('a').attr ('k', '')
            strVar.find ('a').attr ('data-id', (Number(strVar.find ('a').attr('data-id'))+1))
            strVar.find ('img').attr ('src', '')
            strVar.find ('.option-size option[value=""]').attr ("selected", true)
            strVar.find ('.option-color option[value=""]').first ().attr ("selected", true)
            strVar.find ('input[name="sku[ali_size][]"]').attr ('value', '')
            strVar.find ('input[name="sku[ali_color][]"]').attr ('value', '')
            strVar.find ('input[name="sku[sku_id][]"]').attr ('value', '')
            strVar.find ('input[name="sku[sku_num_sn][]"]').attr ('value', '')


            $ ('#sku-list tbody').append (strVar);
            $ ('#sku-list tr:last td:last').html ('<button class="btn btn-warning btn-xs sku-del" type="button">删除</button>');
        });
        $ ('#sku-list').on ('click', '.sku-del', function () {
            $ (this).parents ('tr').remove ();
        });

        $ ('#admin_id').change (function () {

            $.post ('<?php echo base_url('Product/get_goods_sn');?>', {admin_id: $ (this).val ()}, function (goods_sn) {
                $ ('#goods_sn').val (goods_sn);
            }, 'text');
        });

        $ ('#summernote').summernote ({
            tabsize: 2,
            height: 300,
            lang: 'zh-CN'
        });

        state = {
            fileBatch: [],
            isUploading: false,
            isOverLimit: false,
            listIndex: 0
        };
        $ ('.js-uploader__box').uploader ({
            'selectButtonCopy': '请选择或拖拽文件',
            'instructionsCopy': '你可以选择或拖拽多个文件',
            'submitButtonCopy': '上传选择的文件',
            'furtherInstructionsCopy': '你可以选择或拖拽更多的文件',
            'secondarySelectButtonCopy': '选择更多的文件',
            'ajaxUrl': '<?php echo base_url('Product/up_images');?>'
        });


        $ ('#commentForm').submit (function () {
            $('#admin_id').attr('disabled', false)
            var colors = [];
            $ (this).serializeArray ().map (function (item) {
                if (item.name == "sku[color][]") {
                    colors.push (item.value)
                }
            });
            var sizes = [];
            $ (this).serializeArray ().map (function (item) {
                if (item.name == "sku[size][]") {
                    sizes.push (item.value)
                }
            });
            var attribute = [];
            colors.forEach ((item, index) => {
                var obj = {};
                sizes.forEach ((items, indexs) => {
                    if (index === indexs) {
                        obj.name = colors[ index ];
                        obj.value = sizes[ indexs ];
                        attribute.push (obj);
                    }
                })
            });
            // for (var i = 0; i < attribute.length; i++) {
            //     for (var j = i + 1; j < attribute.length; j++) {
            //         if (attribute[i].name == attribute[j].name && attribute[i].value==attribute[j].value) {
            //             alert('有重复数据，请检查')
            //             return;
            //         }
            //     }
            // }
            $ ('.panel-footer .btn-big').attr ('disabled', 'disabled').addClass ('btn-submit-disabled').html ('正在提交，请稍等...');
            var data = new FormData (this);
            $ (".uploader__file-list__item").each (function (i) {
                var index = $ (this).attr ('data-index');
                for (var i = 0; i < state.fileBatch.length; i++) {

                    if (state.fileBatch[ i ] && state.fileBatch[ i ].id === parseInt (index)) {
                        data.append ('files' + index, state.fileBatch[ i ].file, state.fileBatch[ i ].fileName);
                        break;
                    }
                }
                data.append ("files_sort[" + index + "]", $ (this).attr ('data-sku-id'));
            });
            $.ajax ({
                type: 'POST',
                url: '<?php echo base_url('Baby/pets_goods');?>',
                data: data,
                success: function (data) {
                    //clearTimeout (t);
                    if (data.status != 'success') {
                        swal ({
                            title: data.info,
                            text: '2秒后关闭',
                            type: data.status,
                            allowOutsideClick: false,
                            timer: 1500,
                            showConfirmButton: false
                        });
                        $ ('.panel-footer .btn-big').attr ("disabled", false).removeClass ('btn-submit-disabled').html ('提交信息');
                    }
                    else {
                        swal ({
                            title: data.info,
                            text: '2秒后关闭',
                            type: data.status,
                            allowOutsideClick: false,
                            timer: data.stop ? data.stop : 1500,
                            showConfirmButton: false
                        }).then (function (isConfirm) {
                            window.onbeforeunload = '';
                            window.location.href = '<?php echo base_url('Baby/pets_goods_list');?>';
                        });
                        $ ('.panel-footer .btn-big').removeClass ('btn-submit-disabled').html (data.info);
                    }

                },
                dataType: 'json',
                cache: false,
                contentType: false,
                processData: false
            });

            return false;
        });
    });

    // 点击按钮转换厘米英寸


    $ (".centimeter").click (function () {
        // 循环每个input
        $ ('.goods_attr_table input').each (function (i) {

            // 获取每个val值
            var a = $ (this).val ();

            // 如果里面有-
            if ((a.includes ('-')) && (typeof ($ (this).attr ("target")) == "undefined")) {
                // 把有横杠的转化为数组
                arr = a.split ("-");
                // 乘以倍数并保留小数点
                var b = [ (arr[ 0 ] * 2.54).toFixed (1), (arr[ 1 ] * 2.54).toFixed (1) ];
                c = b.join ("-");

                $ (this).attr ({"value": c});
                $ (this).attr ("target", "_blank")
            }

            // 如果为数字
            else if ((!isNaN (a)) && (typeof ($ (this).attr ("target")) == "undefined")) {
                d = a * 2.54;
                d = d.toFixed (1);

                $ (this).attr ({"value": d});
                $ (this).attr ("target", "_blank")
            }

        });
    });
</script >

</body >
</html >
